home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
prinintr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
16KB
|
454 lines
/* printer interface example v28 */
/****************************************************************
* *
* Copyright 1985, Commodore Amiga Inc. All rights reserved. *
* No part of this program may be reproduced, transmitted, *
* transcribed, stored in retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of *
* Commodore Amiga Incorporated, 983 University Ave, #D *
* Los Gatos, CA 95030 *
* *
****************************************************************/
/*** cdio.c ***/
/*********************************************************************/
/* */
/* Copyright (c) 1985 */
/* Commodore-Amiga, Inc. */
/* All rights reserved. */
/* */
/* No part of this program may be reproduced, transmitted, */
/* transcribed, stored in retrieval system, or translated */
/* into any language or computer language, in any form or */
/* by any means, electronic, mechanical, magnetic, optical, */
/* chemical, manual or otherwise, without the prior written */
/* permission of: */
/* Commodore-Amiga, Inc. */
/* 983 University Ave #D */
/* Los Gatos, CA. 95030 */
/* */
/*********************************************************************/
/*********************************************************************/
/* */
/* Program name: cdio */
/* */
/* Purpose: To provide standard console device interface routines */
/* such as Open, GetChar, PutChar, etc. */
/* */
/* Arguments: (window) - The window to associate the console */
/* device with. Used in CDOpen. */
/* (character) - The char to output. Used in CDPutChar */
/* (string) - The string to output. Used in CDPutStr */
/* */
/* Programer: Stan Shepard */
/* */
/* Date Released: 01-Jun-85 */
/* */
/*********************************************************************/
/*#include "intuall.h"*/
#include "idemoall.h"
struct IOStdReq consoleIO = 0;
struct IOStdReq consoleREADIO = 0;
struct MsgPort consoleMsgPort = 0;
UBYTE consoleReadChar = 0;
int CDOpen(window)
struct Window *window;
{
int error;
/* Open the console device */
consoleIO.io_Data = (char *) window;
consoleIO.io_Length = sizeof(*window);
if ((error = OpenDevice("console.device", 0, &consoleIO, 0)) != 0)
{
kprintf("CDInit OpenDevice error: %d.\n", error);
return(error);
}
/* Set up the message port in the I/O request */
consoleMsgPort.mp_Node.ln_Type = NT_MSGPORT;
consoleMsgPort.mp_Flags = 0;
consoleMsgPort.mp_SigBit = AllocSignal(-1);
consoleMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
AddPort(&consoleMsgPort);
consoleIO.io_Message.mn_ReplyPort = &consoleMsgPort;
/* Start reading */
consoleREADIO = consoleIO;
queue_read();
return(0);
}
CDClose()
{
RemPort(&consoleMsgPort);
CloseDevice(&consoleIO);
}
int CDMayGetChar()
{
register temp;
if ( GetMsg(&consoleMsgPort) == NULL ) return(-1);
temp = consoleReadChar;
queue_read();
return(temp);
}
queue_read()
{
consoleREADIO.io_Command = CMD_READ;
consoleREADIO.io_Data = &consoleReadChar;
consoleREADIO.io_Length = 1;
SendIO(&consoleREADIO); /* Due to bug in DoIO */
}
UBYTE CDGetChar()
{
register temp;
while (GetMsg(&consoleMsgPort) == NULL) ; /* during console IO */
temp = consoleReadChar;
queue_read();
return(temp);
}
CDPutChar(character)
char character;
{
consoleIO.io_Command = CMD_WRITE;
consoleIO.io_Data = &character;
consoleIO.io_Length = 1;
DoIO(&consoleIO);
}
CDPutStr(string)
char *string; /* NULL termiinated string to output */
{
consoleIO.io_Command = CMD_WRITE;
consoleIO.io_Data = string;
consoleIO.io_Length = 0;
DoIO(&consoleIO);
}
/*** pio.c ***/
#include "exec/types.h"
#include "exec/nodes.h"
#include "exec/lists.h"
#include "exec/memory.h"
#include "exec/ports.h"
#include "exec/libraries.h"
#include "exec/devices.h"
#include "exec/tasks.h"
#include "exec/io.h"
#include "exec/interrupts.h"
#include "../printer/printer.h"
union {
struct IOStdReq ios;
struct IODRPReq iodrp;
struct IOPrtCmdReq iopc;
} printerIO;
struct MsgPort replyMsgPort;
VOID pWrite(buffer,count)
char *buffer;
long count;
{
char *b;
/* queue a printer write */
printerIO.ios.io_Command = CMD_WRITE;
printerIO.ios.io_Data = buffer;
printerIO.ios.io_Length = count;
DoIO(&printerIO);
};
VOID pDumpRPort(rastPort, colorMap, modes, sx,sy, sw,sh, dc,dr, special)
struct RastPort *rastPort;
UWORD *colorMap;
ULONG modes;
int sx, sy, sw, sh, dc, dr;
UWORD special;
{
printerIO.iodrp.io_Command = PRD_DUMPRPORT;
printerIO.iodrp.io_RastPort = rastPort;
printerIO.iodrp.io_ColorMap = colorMap;
printerIO.iodrp.io_Modes = modes;
printerIO.iodrp.io_SrcX = sx;
printerIO.iodrp.io_SrcY = sy;
printerIO.iodrp.io_SrcWidth = sw;
printerIO.iodrp.io_SrcHeight = sh;
printerIO.iodrp.io_DestCols = dc;
printerIO.iodrp.io_DestRows = dr;
printerIO.iodrp.io_Special = special;
DoIO(&printerIO);
};
int pOpen(signal)
int signal;
{
int error;
kprintf(" attempting to open the printer device \n");
/* open the printer device */
if ((error = OpenDevice("printer.device", 0, &printerIO, 0)) != 0)
{
kprintf("EventInit \"printer.device\" OpenDevice error: %d.\n", error);
return(error);
}
kprintf("ior.error= %ld\n", printerIO.ios.io_Error);
kprintf("printer.device: %lx.\n", printerIO.ios.io_Device);
/* set up the message port in the I/O request */
replyMsgPort.mp_Node.ln_Type = NT_MSGPORT;
replyMsgPort.mp_Flags = 0;
if (signal >= 0)
{
kprintf("Printer signal: %ld\n", signal);
replyMsgPort.mp_SigBit = signal;
replyMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
}
else
{
kprintf("Warning. printer set up for immediate I/O only.\n");
replyMsgPort.mp_SigBit = 0;
replyMsgPort.mp_SigTask = 0;
}
AddPort(&replyMsgPort);
printerIO.ios.io_Message.mn_ReplyPort = &replyMsgPort;
}
pClose()
{
CloseDevice(&printerIO);
RemPort(&replyMsgPort);
}
/*** test.c ***/
/*********************************************************************/
/* */
/* Copyright (c) 1985 */
/* Commodore-Amiga, Inc. */
/* All rights reserved. */
/* */
/* No part of this program may be reproduced, transmitted, */
/* transcribed, stored in retrieval system, or translated */
/* into any language or computer language, in any form or */
/* by any means, electronic, mechanical, magnetic, optical, */
/* chemical, manual or otherwise, without the prior written */
/* permission of: */
/* Commodore-Amiga, Inc. */
/* 983 University Ave #D */
/* Los Gatos, CA. 95030 */
/* */
/*********************************************************************/
/*********************************************************************/
/* */
/* Program name: printer test (built on pic) */
/* */
/* Arguments: (none) */
/* */
/* Notes: 1. Open various libraries. */
/* 2. Open a custom screen and window. */
/* 3. Open & associate a console device with the window. */
/* 4. Draw some simple colored patterns into the window. */
/* 5. Execute printer commands from the console. */
/* 6. Close the window. */
/* */
/* Programer: Stan Shepard */
/* */
/* Date Released: 11-Jun-85 */
/* */
/* Modified: 14-Jun-85 by David Berezowski for V25.22 update */
/* 15-Jun-85 by Kodiak for printer device test */
/* 17-Jun-85 by Andy for parallel&printer test
/* */
/*********************************************************************/
#include "intuall.h"
#include "../printer/printer.h"
#define getc() Read(stdin, c, 2)
#define TXHEIGHT 8
static UWORD colormap[] = { 0xfff, 0xf00, 0x0f0, 0x00f,
0xff0, 0xf0f, 0x0ff, 0x000};
struct TextAttr TestFont =
{
"topaz.font",
TXHEIGHT,
0,
0,
};
long GfxBase = 0;
long IntuitionBase = 0;
struct Screen *OpenScreen();
struct Window *OpenWindow();
main()
{
struct Window *w;
struct Screen *screen;
struct RastPort *rp, *cdrp;
struct ViewPort *vp;
struct IntuiMessage *message;
ULONG cdio;
SHORT i;
SHORT inputChar;
int ch;
UBYTE c[10];
char *b, buffer[80];
int Length;
static char *slash ="/";
GfxBase = OpenLibrary("graphics.library", 0);
if (GfxBase == NULL)
{
printf("Unable to open graphics library\n");
exit();
}
IntuitionBase = OpenLibrary("intuition.library", 0);
if (IntuitionBase == NULL)
{
printf("Unable to open Intuition library\n");
exit();
}
/* Open a custom HIRES screen 3 planes deep */
{
struct NewScreen ns;
ns.LeftEdge = 0;
ns.TopEdge = 0;
ns.Width = 640;
ns.Height = 200;
ns.Depth = 3;
ns.DetailPen = 0;
ns.BlockPen = 1;
ns.ViewModes = HIRES;
ns.Type = CUSTOMSCREEN;
ns.Font = &TestFont;
ns.DefaultTitle = "HIGH RES, 3 planes, for printer test";
ns.Gadgets = NULL;
screen = OpenScreen(&ns); /* open the screen! */
}
if (screen == NULL)
{
printf("Can't open a new screen\n");
exit();
}
{
struct NewWindow nw;
nw.LeftEdge = 0;
nw.TopEdge = 0;
nw.Width = 640;
nw.Height = 200;
nw.DetailPen = -1;
nw.BlockPen = -1;
nw.Flags = WINDOWDEPTH|WINDOWSIZING|WINDOWDRAG|WINDOWCLOSE|ACTIVATE;
nw.IDCMPFlags = CLOSEWINDOW;
nw.FirstGadget = 0;
nw.CheckMark = 0;
nw.Title = "printer test window";
nw.Type = CUSTOMSCREEN;
nw.Screen = screen;
nw.BitMap = NULL;
nw.MinWidth = 80;
nw.MinHeight = 15;
nw.MaxWidth = 10000;
nw.MaxHeight = 10000;
w = OpenWindow(&nw); /* open the window! */
}
rp = w->RPort;
vp = &w->WScreen->ViewPort;
/* Open the console device */
CDOpen(w);
/* Draw some horizontal bars */
for (i = 1; i < 8; i++)
{
SetAPen(rp,i);
RectFill(rp,20,i*10+20,550,i*10+30);
}
/* Draw some verticle bars */
for (i = 1; i < 8; i++)
{
SetAPen(rp,i);
RectFill(rp,0+(i-1)*40,100,39+(i-1)*40,160);
}
/* Set the color registers */
SetRGB4(vp,0,15,15,15); /* White */
SetRGB4(vp,1,15,00,00); /* Red */
SetRGB4(vp,2,00,15,00); /* Green */
SetRGB4(vp,3,00,00,15); /* Blue */
SetRGB4(vp,4,15,15,00); /* Yellow */
SetRGB4(vp,5,15,00,15); /* Magenta */
SetRGB4(vp,6,00,15,15); /* Cyan */
SetRGB4(vp,7,00,00,00); /* Black */
kprintf("use console\n");
CDPutStr("\33[20h"); /* line feed new line mode */
kprintf("open printer\n");
pOpen(AllocSignal(-1));
kprintf("printer is open\n");
/* Wait for a CLOSEWINDOW */
CDPutStr("\nEnter command [w,c]: ");
while (TRUE)
{
message = (struct IntuiMessage *)GetMsg(w->UserPort);
if((message->Class)==CLOSEWINDOW)
{
kprintf("closing up\n");
CDClose();
pClose();
CloseWindow(w);
CloseScreen(screen);
OpenWorkBench();
exit(0);
}
if((ch=CDMayGetChar()) != -1)
{
CDPutChar(ch);
switch (ch) {
case 'w':
CDPutStr("\n string: ");
b = buffer;
while((*b = CDGetChar()) != '.')
{if (*b == '/') { *b++ ='\033'; CDPutChar(*slash);}
else CDPutChar(*b++);
};
CDPutChar(*b++='\n');
*b = '\0';
pWrite(buffer,-1);
break;
case 'c':
pWrite("Thi\033[4mtest\033[0ms is a test\nnow for\033[4",-1);
pWrite("munderlineok ?????\n",-1);
pWrite("ok ?????\n",-1);
pWrite("564 characters were in this test line, have fun.",-1);
pWrite("\nlast line\n",-1);
break;
default:;
}
CDPutStr("\nEnter command [w,c]: ");
}
}
}